package com.zw.yzk.kabu.view.widget;

import android.content.Context;
import android.graphics.Point;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.zw.yzk.kabu.R;


/**
 * Created by wei on 2015/12/29.
 */
public class AlertDialogUtil {

    public static AlertDialog showSelectSexDialog(Context context,
                                                  final View.OnClickListener maleListener,
                                                  final View.OnClickListener femaleListener) {
        View rootView = LayoutInflater.from(context).inflate(R.layout.dialog_select_sex, null);
        //创建对话框
        final AlertDialog dialog = new AlertDialog.Builder(context).setView(rootView).setCancelable(true).create();
        //设置背景透明
        Window window = dialog.getWindow();
        window.setBackgroundDrawableResource(android.R.color.transparent);
        //点击对话框外消失
        dialog.setCanceledOnTouchOutside(true);
        //设置对话框显示位置
        WindowManager.LayoutParams params = window.getAttributes();
        Point windowInfo = new Point();
        window.getWindowManager().getDefaultDisplay().getSize(windowInfo);
        params.y = windowInfo.y;
        //设置对话框动画
        window.setWindowAnimations(R.style.dialog_bottom_in_out_style);
        //设置按键监听事件
        rootView.findViewById(R.id.male).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (maleListener != null) {
                    maleListener.onClick(v);
                }
                dialog.dismiss();
            }
        });
        rootView.findViewById(R.id.female).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (femaleListener != null) {
                    femaleListener.onClick(v);
                }
                dialog.dismiss();
            }
        });
        rootView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        return dialog;
    }

}
